// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cantor/unresolved/visitor.h>

namespace cantor::unresolved {

    class UnresolvedTableRef;
    class UnresolvedRangeVar;
    class UnresolvedWhereClause;
    class UnresolvedOrderByClause;
    class UnresolvedLimitClause;
    class UnresolvedTableName;

    class UnresolvedDeleteStmt : public UnresolvedVisitor<UnresolvedDeleteStmt> {
    public:
        static constexpr const cantor::pb::ast::StmtType TYPE = cantor::pb::ast::StmtType::STMT_DELETE;

        UnresolvedDeleteStmt(const cantor::pb::ast::DeleteStmt &node) :
                                                                     instance(node) {
        }

        UnresolvedDeleteStmt(const cantor::pb::ast::Statement &node) : instance(node.delete_stmt()) {
        }

        ~UnresolvedDeleteStmt() override = default;

        const pb::Location& location_impl() const {
            return  instance.location();
        }

        const pb::Status &error_status_impl() const {
            return  instance.status();
        }

        cantor::pb::ast::PriorityEnum priority(cantor::pb::ast::PriorityEnum v = cantor::pb::ast::PE_NO_PRIORITY) const {
            if (instance.has_priority()) {
                return instance.priority();
            }
            return v;
        }

        bool is_ignore(bool f = false) const {
            if (instance.has_is_ignore()) {
                return instance.is_ignore();
            }
            return f;
        }

        bool is_quick(bool f = false) const {
            if (instance.has_is_quick()) {
                return instance.is_quick();
            }
            return f;
        }

        bool has_from_table() const {
            return instance.has_from_table();
        }

        UnresolvedTableRef from_table () const;

        bool has_table_name() const {
            return instance.has_table_name();
        }

        UnresolvedTableName table_name() const;

        size_t delete_table_list_size() const {
            return instance.delete_table_list_size();
        }

        UnresolvedTableName delete_table_lis(int index) const;

        size_t partition_names_size() const {
            return instance.partition_names_size();
        }

        std::string_view partition_names(int index) const {
            return instance.partition_names(index);
        }

        bool has_where_clause() const {
            return instance.has_where();
        }

        UnresolvedWhereClause where_clause() const;

        bool has_order_clause() const {
            return instance.has_order();
        }

        UnresolvedOrderByClause order_clause() const;

        bool has_limit_clause() const {
            return instance.has_limit();
        }

        UnresolvedLimitClause limit_clause() const;


        const cantor::pb::ast::DeleteStmt &instance;
    };
} // namespace cantor::unresolved
